package simple.game;

import javax.microedition.khronos.opengles.GL10;

import simple.engine.SimpleEngine;
import simple.engine.drawable.SimpleObject;
import simple.engine.managers.ScreenManager;
import simple.engine.managers.TextureManager;
import simple.engine.objects.Texture2D;
import simple.engine.world.SimpleScene;
import android.graphics.BitmapFactory;
import android.view.MotionEvent;

public class SimpleGame extends SimpleEngine {	
	
	SimpleScene mScene = new SimpleScene();
	
	SimpleObject obj;
	
	public SimpleGame()
	{
		mScene.getCamera().setPosition(0, 0, 240);
		mScene.getCamera().setPositionLimit(400, 400, 240, 240);
		obj = mScene.addChild(new SimpleObject("xx",0,0,144,144));
	}
	
	@Override
	protected void onAppCreate(GL10 gl) {
		Texture2D x = TextureManager.loadTexture(gl, "id", BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
		obj.setTexture(x);
	}
	
	@Override
	protected void onAppDestroy() {
		mScene.destroy();
	}
	
	@Override
	protected void onGameUpdate(float gtc) {
		/*if(Math.random() < 0.02)
		{
			mScene.addChild(new SimpleObject(System.currentTimeMillis() + "", (float) Math.random() * 700 + 50, (float) Math.random() * 400 + 40, 100, 100));
		}*/
		obj.move(1.0f, 1.0f);
	}

	@Override
	protected void onGameDraw(GL10 gl) {
		mScene.drawScene(gl);
	}

	@Override
	protected void onPointerTouch(MotionEvent event) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	protected void onPointerDown(float x, float y) {
		// TODO Auto-generated method stub
		float[] coords = ScreenManager.getClickedWorldCoords(x, y, mScene.getCamera().getX(), mScene.getCamera().getY());
		mScene.removeChild(mScene.getClickedChild(coords[0], coords[1]));
	}

	@Override
	protected void onPointerMove(float x, float y, float lastX, float lastY) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void onPointerUp() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void onPointerHold(float x, float y, long ms) 
	{
		
	}
}